#import "SEGRootViewModel.h"

@interface SEGRootViewModel()
@end

@implementation SEGRootViewModel
#pragma mark - Init
-(instancetype)init{
    if (self = [super init]) {
        NSLog(@"%s",__func__);

        [self racInit];
    }
    return self;
}

-(void)dealloc {
    NSLog(@"%s",__func__);
    [self.requestCommand rac_deallocDisposable];
    [self.messageSubject rac_deallocDisposable];

}

- (void)racInit {
    [self seg_requestCommand];

}

#pragma mark - Publish Methods

#pragma mark - Private Methods
/// show message
-(void)seg_showMessage:(NSString*)msg code:(NSInteger)code{
    [self.messageSubject sendNext:@{@"code":@(code),@"msg":msg}];
}

-(void)seg_requestCommand{
    //@weakify(self);
    _requestCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            //@strongify(self);
            
            // Code here...
            // [subscriber sendNext:nil];
            // [subscriber sendCompleted];

            // NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey:@"error!"}];
            // [subscriber sendError:error];            
            return [RACDisposable disposableWithBlock:^{
            }];
        }];
    }];
}


#pragma mark - Getter
-(RACSubject *)messageSubject{
    if (!_messageSubject) {
        _messageSubject = [RACSubject subject];
    }
    return _messageSubject;
}

#pragma mark - Stter
@end
